package main

import (
	"database/sql"
	"log"

	_ "modernc.org/sqlite"
)

var DB *sql.DB

func InitDB() {
	var err error
	DB, err = sql.Open("sqlite", "./alerts.db")
	if err != nil {
		log.Fatalf("打开数据库失败: %v", err)
	}

	createTableSQL := `
	CREATE TABLE IF NOT EXISTS alerts (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		type TEXT NOT NULL,
		timestamp REAL NOT NULL,
		image_base64 TEXT
	);
	`
	_, err = DB.Exec(createTableSQL)
	if err != nil {
		log.Fatalf("建表失败: %v", err)
	}

	log.Println("数据库初始化完成")
}
